<?php

namespace app\admin\model\product;

use think\Model;
use traits\model\SoftDelete;

class Chassis extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'product_chassis';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'zhuban_text',
        'shuileng_text',
    ];
    

    public function getZhubanList()
    {
        return ['E-ATX(加强型)' => __('E-ATX(加强型)'), 'ATX(标准型)' => __('ATX(标准型)'),
            'M-ATX(紧凑型)' => __('M-ATX(紧凑型)'), 'MINI-ITX(迷你型)' => __('MINI-ITX(迷你型)'),
        ];
    }


    public function getZhubanTextAttr($value, $data)
    {
        $value = $value ? $value : $data['zhuban'];
        $valueArr = explode(',', $value);
        $list = $this->getZhubanList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }





    public function getShuilengList()
    {
        return ['420冷排' => __('420冷排'), '360冷排' => __('360冷排'), '280冷排' => __('280冷排'),
            '240冷排' => __('240冷排'),'120冷排' => __('120冷排')
        ];
    }


    public function getShuilengTextAttr($value, $data)
    {
        $value = $value ? $value : $data['shuileng'];
        $valueArr = explode(',', $value);
        $list = $this->getShuilengList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function brand()
    {
        return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function product()
    {
        return $this->belongsTo('app\admin\model\Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
